home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / cp950.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  3.5 KB  |  114 lines

  1.  
  2. /*
  3.  * CP950
  4.  */
  5.  
  6. /*
  7.  * Microsoft CP950 is a slightly extended and slightly modified version of
  8.  * BIG5. The differences between the EASTASIA/OTHER/BIG5.TXT and
  9.  * VENDORS/MICSFT/WINDOWS/CP950.TXT tables found on ftp.unicode.org are
  10.  * as follows:
  11.  *
  12.  * 1. Some characters in the BIG5 range are defined differently:
  13.  *
  14.  *     code   BIG5.TXT                       CP950.TXT
  15.  *    0xA145  0x2022 # BULLET                0x2027 # HYPHENATION POINT
  16.  *    0xA14E  0xFF64 # HALFWIDTH IDEOGRAPHIC COMMA
  17.  *                                           0xFE51 # SMALL IDEOGRAPHIC COMMA
  18.  *    0xA15A    ---                          0x2574 # BOX DRAWINGS LIGHT LEFT
  19.  *    0xA1C2  0x203E # OVERLINE              0x00AF # MACRON
  20.  *    0xA1C3    ---                          0xFFE3 # FULLWIDTH MACRON
  21.  *    0xA1C5    ---                          0x02CD # MODIFIER LETTER LOW MACRON
  22.  *    0xA1E3  0x223C # TILDE OPERATOR        0xFF5E # FULLWIDTH TILDE
  23.  *    0xA1F2  0x2641 # EARTH                 0x2295 # CIRCLED PLUS
  24.  *    0xA1F3  0x2609 # SUN                   0x2299 # CIRCLED DOT OPERATOR
  25.  *    0xA1FE    ---                          0xFF0F # FULLWIDTH SOLIDUS
  26.  *    0xA240    ---                          0xFF3C # FULLWIDTH REVERSE SOLIDUS
  27.  *    0xA241  0xFF0F # FULLWIDTH SOLIDUS     0x2215 # DIVISION SLASH
  28.  *    0xA242  0xFF3C # FULLWIDTH REVERSE SOLIDUS
  29.  *                                           0xFE68 # SMALL REVERSE SOLIDUS
  30.  *    0xA244  0x00A5 # YEN SIGN              0xFFE5 # FULLWIDTH YEN SIGN
  31.  *    0xA246  0x00A2 # CENT SIGN             0xFFE0 # FULLWIDTH CENT SIGN
  32.  *    0xA247  0x00A3 # POUND SIGN            0xFFE1 # FULLWIDTH POUND SIGN
  33.  *    0xA2CC    ---                          0x5341
  34.  *    0xA2CE    ---                          0x5345
  35.  *
  36.  *    We don't implement these changes.
  37.  *
  38.  * 2. A small new row. See cp950ext.h.
  39.  *
  40.  * 3. CP950.TXT is lacking the range 0xC6A1..0xC7FC (Hiragana, Katakana,
  41.  *    Cyrillic, circled digits, parenthesized digits).
  42.  *
  43.  *    We implement this omission, because said range is marked "uncertain"
  44.  *    in the unicode.org BIG5 table.
  45.  */
  46.  
  47. #include "cp950ext.h"
  48.  
  49. static int
  50. cp950_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  51. {
  52.   unsigned char c = *s;
  53.   /* Code set 0 (ASCII) */
  54.   if (c < 0x80)
  55.     return ascii_mbtowc(conv,pwc,s,n);
  56.   /* Code set 1 (BIG5 extended) */
  57.   if (c >= 0xa1 && c < 0xff) {
  58.     if (n < 2)
  59.       return RET_TOOFEW(0);
  60.     {
  61.       unsigned char c2 = s[1];
  62.       if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {
  63.         if (!((c == 0xc6 && c2 >= 0xa1) || c == 0xc7)) {
  64.           int ret = big5_mbtowc(conv,pwc,s,2);
  65.           if (ret != RET_ILSEQ)
  66.             return ret;
  67.         }
  68.       }
  69.     }
  70.     if (c == 0xf9) {
  71.       int ret = cp950ext_mbtowc(conv,pwc,s,2);
  72.       if (ret != RET_ILSEQ)
  73.         return ret;
  74.     }
  75.   }
  76.   return RET_ILSEQ;
  77. }
  78.  
  79. static int
  80. cp950_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  81. {
  82.   unsigned char buf[2];
  83.   int ret;
  84.  
  85.   /* Code set 0 (ASCII) */
  86.   ret = ascii_wctomb(conv,r,wc,n);
  87.   if (ret != RET_ILSEQ)
  88.     return ret;
  89.  
  90.   /* Code set 1 (BIG5 extended) */
  91.   ret = big5_wctomb(conv,buf,wc,2);
  92.   if (ret != RET_ILSEQ) {
  93.     if (ret != 2) abort();
  94.     if (!((buf[0] == 0xc6 && buf[1] >= 0xa1) || buf[0] == 0xc7)) {
  95.       if (n < 2)
  96.         return RET_TOOSMALL;
  97.       r[0] = buf[0];
  98.       r[1] = buf[1];
  99.       return 2;
  100.     }
  101.   }
  102.   ret = cp950ext_wctomb(conv,buf,wc,2);
  103.   if (ret != RET_ILSEQ) {
  104.     if (ret != 2) abort();
  105.     if (n < 2)
  106.       return RET_TOOSMALL;
  107.     r[0] = buf[0];
  108.     r[1] = buf[1];
  109.     return 2;
  110.   }
  111.  
  112.   return RET_ILSEQ;
  113. }
  114.